package Preferences;

import android.content.Context;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.preference.Preference;
import static android.content.Context.MODE_PRIVATE;

/**
 * @author zelonghu
 * @name test_all_without_network
 * @class name：Preferences
 * @class 用于存储系统的设置 to save the saving of the system
 * @time 2019/4/23 3:47 PM
 * @change
 * @chang time
 * @class describe
 */
public class Preferences extends Preference {
    private Context context;

    public Preferences(Context context) {
        super(context);
        this.context = context;
    }



    /**
     * @author zelonghu
     * @time 2019/6/25  3:14 PM
     * @describe 存储登录信息，没有是0，0，0
     */
    public void save_login_info(String imagepath,String username,String userintroduce){
        SharedPreferences p = context.getSharedPreferences("login", MODE_PRIVATE);
        SharedPreferences.Editor editor = p.edit();
        editor.putString("imagepath",imagepath);
        editor.putString("username",username);
        editor.putString("userintroduce",userintroduce);
        editor.commit();
    }

    /**
     * @author zelonghu
     * @time 2019/6/25  3:26 PM
     * @describe 获取登录信息，没有是0，0，0
     */
    public Bundle get_login_info(){
        SharedPreferences p = context.getSharedPreferences("login",MODE_PRIVATE);
        if(p!=null){
            Bundle bundle = new Bundle();
            bundle.putString("imagepath",p.getString("imagepath",""));
            bundle.putString("username",p.getString("username",""));
            bundle.putString("userintroduce",p.getString("userintroduce",""));
            return bundle;
        }else{
            return null;
        }
    }

    /**
     * @author zelonghu
     * @time 2019/6/25  3:45 PM
     * @describe 判断用户名密码是否合法
     */
    public boolean isValid(String username,String password){
        if(username.length()<20 && password.length()<20&&username.length()>0&& password.length()>0)
            return true;
        else
            return false;
    }





}
